package cn.cocho.module.common.web.mail;

import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: shk
 * Date: 14-5-15
 * Time: 下午11:30
 * To change this template use File | Settings | File Templates.
 */
public class MailSendDemo {

    static MailSendTools mailSendTools = new MailSendTools();

    public static void main(String[] args) throws Exception {
        MailSendAccountInfo mailSendAccountInfo = new MailSendAccountInfo();
        mailSendAccountInfo.setEmailHost("smtp.163.com");
        mailSendAccountInfo.setEmailFrom("songhaikang@163.com");
        mailSendAccountInfo.setEmailUserName("songhaikang@163.com");
        mailSendAccountInfo.setEmailPassword("");//此处需要填写密码
        mailSendTools.setSendAccountInfo(mailSendAccountInfo);

//        mailSendAccountInfo.setEmailHost("smtp.qq.com");
//        mailSendAccountInfo.setEmailFrom("940050218@qq.com");
//        mailSendAccountInfo.setEmailUserName("940050218@qq.com");
//        mailSendAccountInfo.setEmailPassword("");


        test1();
        test2();
        test3();
        test4();
        test5();
        test6();

    }

    public static void test1() throws Exception {
        MailReceiveInfo mailReceiveInfo = new MailReceiveInfo();
        mailReceiveInfo.setToEmails("940050218@qq.com");
        mailReceiveInfo.setSubject("Email Test 第一封，简单文本邮件");
        mailReceiveInfo.setContent("我相信天上不会掉馅饼");
        mailSendTools.sendEmail(mailReceiveInfo);
    }

    public static void test2() throws Exception {
        MailReceiveInfo mailReceiveInfo = new MailReceiveInfo();
        mailReceiveInfo.setToEmails("940050218@qq.com");
        mailReceiveInfo.setSubject("Email Test 第二封，html片段");
        mailReceiveInfo.setContent("<html><body>老婆：<br />我是你的老公吗？<br />是的，是很久了。<br /></body></html>");
        mailSendTools.sendEmail(mailReceiveInfo);
    }

    public static void test3() throws Exception {
        Map<String, String> pictures = new HashMap<String, String>();
        pictures.put("d1", "/Users/shk/Desktop/temp/1.jpg");
        pictures.put("d2", "/Users/shk/Desktop/temp/2.jpg");
        pictures.put("d3", "/Users/shk/Desktop/temp/3.jpg");

        StringBuilder builder = new StringBuilder();
        builder.append("<html><body>看看下面的图，你会知道花儿为什么是这样红的：<br />");
        builder.append("<img src=\"cid:d1\" /><br />");
        builder.append("<img src=\"cid:d2\" /><br />");
        builder.append("<img src=\"cid:d3\" /><br />");
        builder.append("</body></html>");
        String content = builder.toString();


        MailReceiveInfo mailReceiveInfo = new MailReceiveInfo();
        mailReceiveInfo.setToEmails("940050218@qq.com");
        mailReceiveInfo.setSubject("Email Test 第三封，带图片");
        mailReceiveInfo.setContent(content);
        mailReceiveInfo.setPictures(pictures);
        mailSendTools.sendEmail(mailReceiveInfo);
    }

    public static void test4() throws Exception {
        Map<String, String> attachments = new HashMap<String, String>();
        attachments.put("d1.jar", "/Users/shk/Desktop/temp/test.rar");
        attachments.put("测试附件.doc", "/Users/shk/Desktop/temp/test.doc");
//        attachments.put("d2.doc", "/Users/shk/Desktop/temp/人月神话.txt");
        StringBuilder builder = new StringBuilder();
        builder.append("<html><body>看看附件中的资料，你会知道世界为什么是平的。</body></html>");
        String content = builder.toString();


        MailReceiveInfo mailReceiveInfo = new MailReceiveInfo();
        mailReceiveInfo.setToEmails("940050218@qq.com");
        mailReceiveInfo.setSubject("Email Test 第四封，带附件");
        mailReceiveInfo.setContent(content);
        mailReceiveInfo.setAttachments(attachments);
        mailSendTools.sendEmail(mailReceiveInfo);

    }

    public static void test5() throws Exception {
        Map<String, String> attachments = new HashMap<String, String>();
        attachments.put("d1.jar", "/Users/shk/Desktop/temp/test.rar");
        attachments.put("d2.doc", "/Users/shk/Desktop/temp/test.doc");

        Map<String, String> pictures = new HashMap<String, String>();
        pictures.put("d1", "/Users/shk/Desktop/temp/1.jpg");
        pictures.put("d2", "/Users/shk/Desktop/temp/2.jpg");
        pictures.put("d3", "/Users/shk/Desktop/temp/3.jpg");

        StringBuilder builder = new StringBuilder();
        builder.append("<html><body>看看附件中的资料，你会知道世界为什么是平的。<br />");
        builder.append("看看下面的图，你会知道花儿为什么是这样红的：<br />");
        builder.append("<img src=\"cid:d1\" /><br />");
        builder.append("<img src=\"cid:d2\" /><br />");
        builder.append("<img src=\"cid:d3\" /><br />");
        builder.append("</body></html>");
        String content = builder.toString();

        MailReceiveInfo mailReceiveInfo = new MailReceiveInfo();
        mailReceiveInfo.setToEmails("940050218@qq.com");
        mailReceiveInfo.setSubject("Email Test 第五封，综合邮件");
        mailReceiveInfo.setContent(content);
        mailReceiveInfo.setPictures(pictures);
        mailReceiveInfo.setAttachments(attachments);
        mailSendTools.sendEmail(mailReceiveInfo);

    }

    public static void test6() throws Exception {

        Map<String, String> attachments = new HashMap<String, String>();
        attachments.put("d1.jar", "/Users/shk/Desktop/temp/test.rar");
        attachments.put("d2.doc", "/Users/shk/Desktop/temp/test.doc");

        Map<String, String> pictures = new HashMap<String, String>();
        pictures.put("d1", "/Users/shk/Desktop/temp/1.jpg");
        pictures.put("d2", "/Users/shk/Desktop/temp/2.jpg");
        pictures.put("d3", "/Users/shk/Desktop/temp/3.jpg");

        StringBuilder builder = new StringBuilder();
        builder.append("<html><body>看看附件中的资料，你会知道世界为什么是平的。<br />");
        builder.append("看看下面的图，你会知道花儿为什么是这样红的：<br />");
        builder.append("<img src=\"cid:d1\" /><br />");
        builder.append("<img src=\"cid:d2\" /><br />");
        builder.append("<img src=\"cid:d3\" /><br />");
        builder.append("</body></html>");
        String content = builder.toString();

        MailReceiveInfo mailReceiveInfo = new MailReceiveInfo();
        mailReceiveInfo.setToEmails("940050218@qq.com;songhaikang@163.com");
        mailReceiveInfo.setSubject("Email Test 第六封，群发邮件");
        mailReceiveInfo.setContent(content);
        mailReceiveInfo.setPictures(pictures);
        mailReceiveInfo.setAttachments(attachments);
        mailSendTools.sendEmail(mailReceiveInfo);

    }
}
